using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace UM_Model.Models.Mapping
{
    public class ImageMap : EntityTypeConfiguration<Image>
    {
        public ImageMap()
        {
            // Primary Key
            this.HasKey(t => t.ImageID);

            // Properties
            this.Property(t => t.Title)
                .HasMaxLength(100);

            this.Property(t => t.Source)
                .HasMaxLength(200);

            // Table & Column Mappings
            this.ToTable("Images");
            this.Property(t => t.ImageID).HasColumnName("ImageID");
            this.Property(t => t.Title).HasColumnName("Title");
            this.Property(t => t.Source).HasColumnName("Source");
            this.Property(t => t.Album).HasColumnName("Album");
            this.Property(t => t.IsEnable).HasColumnName("IsEnable");

            // Relationships
            this.HasOptional(t => t.Album1)
                .WithMany(t => t.Images)
                .HasForeignKey(d => d.Album);

        }
    }
}
